03. ROS Publishers
ROS Publishers
Before you see the code for
simple_mover
, it may be helpful to see how ROS Publishers work in Python.
Publishers allow a node to send messages to a topic, so that data from the node can be used in other parts of the ROS system. In Python, ROS publishers typically have the following definition format, although other parameters and arguments are possible:
pub1 = rospy.Publisher("/topic_name", message_type, queue_size=size)
The
"/topic_name"
indicates which topic the publisher will be publishing to. The message_type is the type of message being published on "/topic_name".
ROS publishing can be either synchronous or asynchronous:
-
Synchronous publishing means that a publisher will attempt to publish to a topic but may be blocked if that topic is being published to by a different publisher. In this situation, the second publisher is blocked until the first publisher has serialized all messages to a buffer and the buffer has written the messages to each of the topic's subscribers. This is the default behavior of a
rospy.Publisher
if thequeue_size
parameter is not used or set toNone
. -
Asynchronous publishing means that a publisher can store messages in a queue until the messages can be sent. If the number of messages published exceeds the size of the queue, the oldest messages are dropped. The queue size can be set using the
queue_size
parameter.
Once the publisher has been created as above, a
message
with the specified data type can be published as follows:
pub1.publish(message)
For more information about ROS publishers, see the documentation here .
Publisher queue_size
SOLUTION:
`queue_size=2`
Let's get started with
simple_mover
!